package cn.lili.controller.payment;

import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.order.trade.entity.vo.WalletLogQueryVO;
import cn.lili.modules.payment.entity.dos.WalletLog;
import cn.lili.modules.wallet.service.WalletLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 钱包变动日志记录接口
 *
 * @author pikachu
 * @since 2020/11/16 10:07 下午
 */
@RestController
@Api(tags = "钱包变动日志记录接口")
@RequestMapping("/payment/wallet/log")
@RequiredArgsConstructor
public class WalletLogController {

    private final WalletLogService walletLogService;


    @ApiOperation(value = "分页获取预存款充值记录")
    @GetMapping
    public ResultMessage<Page<WalletLog>> getByPage(PageVO page, WalletLogQueryVO walletLogQueryVO) {
        AuthUser currentUser = UserContext.getCurrentUser();
        if (currentUser != null) {
            switch (currentUser.getScene()) {
                case MEMBER -> walletLogQueryVO.setUserId(currentUser.getId());
                case STORE, SUPPLIER, URBAN_SUBSTATION -> walletLogQueryVO.setUserId(UserContext.getCurrentId());
                default -> {}
            }
        }
        //构建查询 返回数据
        Page<WalletLog> depositLogPage = walletLogService.depositLogPage(page, walletLogQueryVO);
        return ResultUtil.data(depositLogPage);
    }
}
